<?php
require "setup.php";
require "top_page.php";
?>

<?php

if(!isset($_GET["album"])) { // On affiche tous les albums
	$res=albums();
	?>

	<h1><?php echo _("Albums"); ?></h1>

	<table class="albums">
		<tr><th><?php echo _("Artist"); ?></th><th><?php echo _("Album's title"); ?></th></tr>
		<?php
		for($i = 1; $i < $res["COUNT"]; $i++) {
			echo "<tr".($i%2 == 0 ? " class=\"pairLine\"" : "")."><td>".$res["$i"][0]."</td><td><div><a href=\"#\" onclick=\"showTracks(".$i.")\">".$res["$i"][1]."</a></div><div id=\"tracks".$i."\" style=\"padding: 10px; display: none\">---</div></td></tr>";
		}
		?>
	</table>

	<?php
} else if(!isset($_GET["track"])) { // On affiche les musiques d'un album
	$res=tracks($_GET["album"]);
	?>
	
	<h1><? echo $res["ALBUMNAME"]; ?></h1>

	<?php 
		track_list(array(_("Artist"), _("Name"), _("Rating")), $res, array("ARTIST", "TITLE", "RATING", "ALBUM_NO", "TRACK_NO"), $res["COUNT"]);
	?>

	<?php
} else { // On affiche une musique en particulier
	$res=info($_GET["album"], $_GET["track"]);
	?>

	<h1><? echo $res["TITLE"]; ?></h1>

	<table class="infotrack">
		<tr><th><?php echo _("Name"); ?></th><td><? echo $res["TITLE"]; ?></td></tr>
		<tr><th><?php echo _("Album"); ?></th><td><a href="albums.php?album=<?php echo $res["ALBUM_NO"] ; ?>"><?php echo $res["ALBUM"]; ?></a></td></tr>
		<tr><th><?php echo _("Artist"); ?></th><td><? echo $res["ARTIST"]; ?></td></tr>
		<tr><th><?php echo _("Duration"); ?></th><td><? echo $res["LENGTH"]; ?></td></tr>
		<tr><th><?php echo _("Played"); ?></th><td><? echo $res["LAST_PLAYED"]; ?></td></tr>
		<tr><th><?php echo _("Genre"); ?></th><td><? echo $res["GENRE"]; ?></td></tr>
		<tr><th><?php echo _("Rated"); ?></th><td><? echo _($res["RATING"]); ?></td></tr>
		<tr><th><?php echo _("Filter"); ?></th><td><? echo $res["FILTER"]; ?></td></tr>
	</table>
	<br/>
	<table class="ratings">
		<tr><th><?php echo _("User"); ?></th><th><?php echo _("Rating"); ?></th></tr>
	<?php
		$res=ratings($_GET["album"], $_GET["track"]);
		for($i = 0; $i < $res["COUNT"]; $i++) {
			echo "<tr><td>".$res["$i"]["USER"]."</td><td>"._($res["$i"]["RATING"])."</td></tr>";
		}
	?>
	</table>

	<p><a class="addqueue" href="queue.php?add=1&amp;album=<?php echo $_GET["album"]; ?>&amp;track=<?php echo $_GET["track"]; ?>"><?php echo _("Add to queue"); ?></a></p>

	<?php
}
?>

<?php
require "bottom_page.php";
?>
